import { z } from 'zod'

const servingUnitSchema = z.intersection(
  z.object({
    name: z.string().min(1).max(255)
  }),
  z.discriminatedUnion('action', [
    z.object({
      action: z.literal('create')
    }),
    z.object({
      action: z.literal('update')
    })
  ])
)

type ServingUnitSchema = z.infer<typeof servingUnitSchema>
const servingUnitDefaultValues: ServingUnitSchema = {
  name: '',
  action: 'create'
}
export { servingUnitSchema, servingUnitDefaultValues, type ServingUnitSchema }
